<template>
	<view class="content">
		<view class="user-list">
			<block v-for="(item, index) in list" :key="index">
				<view v-if="!!item.member" class="user-item" @click="openUserDetails(item.member)">
					<view class="user-avatar">
						<image class="avatar" :src="item.member.avatar + '?imageView2/1/w/100/h/100'" mode="aspectFill"></image>
					</view>
					<view class="info-wrap">
						<view class="user-info">
							<view class="name">
								<text>{{item.member.name}}</text>
							</view>
							<view class="info">
								<view :class="['sex-wrap', 'sex' + item.member.sex]">
									<image class="sex-icon" :src="'/static/img/sex' + item.member.sex + '.png'" mode=""></image>
									<text class="age">{{item.member.age}}</text>
								</view>
							</view>
						</view>
					</view>
					<view class="uni-icon uni-icon-arrowright"></view>
				</view>
			</block>
		</view>
		<uni-load-more :status="status" :content-text="contentText"></uni-load-more>
	</view>
</template>

<script>
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue"
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				myInfo: {},
				list: [],
				page: 1,
				status: 'more',
				contentText: {
					contentdown: '加载更多',
					contentrefresh: '加载中',
					contentnomore: '木有了~'
				},
			}
		},
		onLoad(options) {
			try {
				let myInfo = uni.getStorageSync('myInfo');
				if (myInfo) {
					this.myInfo = myInfo;
				}
			} catch (e) {
				console.log(e);
			}
		},
		onReady() {
			
		},
		onShow() {
			// if (!!getApp().globalData.follow2_list) {
			// 	this.list = getApp().globalData.follow2_list
			// }
			this.getUserFollow();
		},
		onPullDownRefresh() {
			this.page = 1;
			setTimeout(() => {
				this.getUserFollow();
			}, 500)
		},
		onReachBottom() {
			this.status = 'loading';
			this.getUserFollow();
		},
		methods: {
			getUserFollow: function () {
				this.$api.api.ajaxData({
					method: 'V1.UserFollow',
					uid: this.myInfo.id,
					token: this.myInfo.token,
					type: 2,
					page: this.page
				}, res => {
					uni.stopPullDownRefresh();
					if (res.status) {
						var resdata=res.data.data;
						if (this.page == 1) {
							this.list = resdata
							this.page++
							this.status = 'more'
							if (resdata.length == 0) {
								this.status = 'noMore'
							}
						} else {
							if (resdata.length > 0) {
								for (let i = 0; i < resdata.length; i++) {
									this.list.push(resdata[i])
								}
								this.page++
								this.status = 'more'
							} else {
								this.status = 'noMore'
							}
						}
					} else {
						uni.showToast({
							title: res.msg,
							position: 'bottom',
							icon: 'none'
						});
					}
				}, err => {
					uni.hideLoading();
					uni.showToast({
						title: '网络错误，请稍后再试',
						position: 'bottom',
						icon: 'none'
					});
				})
			},
			
			openUserDetails: function (item) {
				let user = {
					id: item.id,
					name: item.name,
					avatar:item.avatar
				}
				uni.navigateTo({
					url: '../home/user_home?user=' + JSON.stringify(user)
				})
			},
		}
	}
</script>

<style lang="scss">
	@import '../../common/common.scss';
	.user-list {
		padding: 1rpx 0;
	}
	.user-item {
		display: flex;
		justify-content: flex-start;
		align-items: center;
		padding: 20rpx;
		background-color: #fff;
		.user-avatar {
			display: flex;
			justify-content: center;
			align-items: center;
			padding: 1rpx;
			border: 4rpx solid #fff;
			border-radius: 120rpx;
			position: relative;
			.avatar {
				width: 100rpx;
				height: 100rpx;
				border-radius: 100rpx;
				background-color: $image-bg-color;
			}
		}
		.info-wrap {
			display: flex;
			justify-content: flex-start;
			align-items: center;
			flex: 1;
			height: 140rpx;
			border-bottom: 1rpx solid #f9f9f9;
		}
		.user-info {
			flex: 1;
			margin: 0 20rpx;
			.name {
				display: flex;
				justify-content: flex-start;
				align-items: center;
				text {
					max-width: 360rpx;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					font-size: 36rpx;
					color: #333;
				}
			}
			.info {
				display: flex;
				justify-content: flex-start;
				align-items: center;
			}
			.sex-wrap {
				display: flex;
				justify-content: center;
				align-items: center;
				line-height: 28rpx;
				padding: 5rpx 10rpx;
				border-radius: 28rpx;
				&.sex1 {
					background: #83d7ff;
				}
				&.sex2 {
					background: #fe9ab7;
				}
				.sex-icon {
					width: 28rpx;
					height: 28rpx;
				}
				.age {
					font-size: 28rpx;
					color: #fff;
					margin-left: 5rpx;
				}
			}
			.city-wrap {
				display: flex;
				justify-content: center;
				align-items: center;
				line-height: 28rpx;
				padding: 5rpx 10rpx;
				border-radius: 28rpx;
				background: #4cbcfc;
				margin-left: 10rpx;
				.city-icon {
					width: 28rpx;
					height: 28rpx;
				}
				.city {
					font-size: 28rpx;
					color: #fff;
					margin-left: 5rpx;
				}
			}
			.intro {
				width: 360rpx;
				font-size: 32rpx;
				color: #999999;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
				margin-top: 10rpx;
			}
		}
		.uni-icon {
			font-size: 28rpx;
			color: #999999;
		}
	}
</style>
